home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / • Extras • / SGI STL / defalloc.h < prev    next >
C/C++ Source or Header  |  1997-05-31  |  3KB  |  103 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  * Copyright (c) 1997
  15.  * Moscow Center for SPARC Technology
  16.  *
  17.  * Permission to use, copy, modify, distribute and sell this software
  18.  * and its documentation for any purpose is hereby granted without fee,
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both that copyright notice and this permission notice appear
  21.  * in supporting documentation.  Moscow Center for SPARC Technology makes no
  22.  * representations about the suitability of this software for any
  23.  * purpose.  It is provided "as is" without express or implied warranty.
  24.  *
  25.  */
  26.  
  27. #ifndef __SGI_STL_DEFALLOC_H
  28. #define __SGI_STL_DEFALLOC_H
  29.  
  30. #include <stddef.h>
  31. #include <stdlib.h>
  32. #include <limits.h>
  33. # ifndef __SGI_STL_ALLOC_H 
  34. #  include <alloc.h>
  35. # endif
  36.  
  37. # ifndef __SGI_STL_ALGOBASE_H 
  38. #  include <algobase.h>
  39. # endif
  40.  
  41. __BEGIN_STL_NAMESPACE
  42.  
  43. // This file is obsolete; provided only for backward compatibility
  44. // with code that use allocator<T>
  45.  
  46. template <class T>
  47. inline T* allocate(size_t size, T*) {
  48.     return 0 == size ? 0 : ::operator new(size*sizeof(T));
  49. }
  50.  
  51. template <class T>
  52. inline void deallocate(T* buffer) {
  53.     ::operator delete(buffer);
  54. }
  55.  
  56. template <class T>
  57. inline void deallocate(T* buffer, size_t) {
  58.     ::operator delete(buffer);
  59. }
  60.  
  61. template <class T>
  62. class allocator : public alloc {
  63.     typedef alloc super;
  64. public:
  65.     typedef T value_type;
  66.     typedef T* pointer;
  67.     typedef const T* const_pointer;
  68.     typedef T& reference;
  69.     typedef const T& const_reference;
  70.     typedef size_t size_type;
  71.     typedef ptrdiff_t difference_type;
  72.     static T* allocate(size_t n=1) { return (T*)super::allocate(n * sizeof(T));}
  73.     static void deallocate(T *p, size_t n=1) { super::deallocate(p, n * sizeof(T)); }
  74.     static pointer address(reference x) { return (pointer)&x; }
  75.     static const_pointer address(const_reference x) { 
  76.     return (const_pointer)&x; 
  77.     }
  78.     static size_type max_size() { 
  79.         size_type sz((size_t)(-1)/sizeof(T));
  80.         size_type msz(1);
  81.     return max(msz, sz);
  82.     }
  83.     // CD2 requires that
  84.     static T* allocate(size_t n, const void* ) { return (T*)super::allocate(n * sizeof(T));}
  85.     void construct(pointer p, const value_type& val) { construct(p, val); }
  86.     void destroy(pointer p) { destroy(p); }
  87. };
  88.  
  89. template<class T1, class T2> inline
  90. bool operator==(const allocator<T1>&, const allocator<T2>&) { return true; }
  91. template<class T1, class T2> inline
  92. bool operator!=(const allocator<T1>&, const allocator<T2>&) { return false; }
  93.  
  94. __STL_FULL_SPECIALIZATION class allocator<void> {
  95. public:
  96.     typedef void* pointer;
  97.     typedef const void* const_pointer;
  98. };
  99.  
  100. __END_STL_NAMESPACE
  101.  
  102. #endif
  103.